package com.rh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rh.entity.CrmBanner;
import com.rh.mapper.CrmBannerMapper;
import com.rh.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 首页banner表 服务实现类
 * @author rh
 * @since 2021-10-13
 */
@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {
    /**
     * 获取首页Banner数据
     */
    @Cacheable(value = "banner",key = "'selectIndexList'")//redis缓存,生成key的规则banner::selectIndexList
    @Override
    public List<CrmBanner> selectAllBanner() {
    //根据id进行降序排序，显示排列之后的两条数据
        QueryWrapper<CrmBanner> wrapper= new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 2");
        List<CrmBanner> list = baseMapper.selectList(wrapper);
        return list;
    }
}
